package FileTree;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.ToolTipManager;

/**
 *
 * @author Krisz
 */
public class TreeTest implements  ActionListener{
    
    JComboBox cb;
    FileTreeModel model;
    
    @Override
    public void actionPerformed(ActionEvent ae) {
	model.setRoot((FileWrap)(cb.getSelectedItem()));
        
    }
	
    public static void main(String args[]){
        (new TreeTest()).run();
    }
	
    public void run(){
        JFrame frame = new JFrame("JTree Example");
		
        model = new FileTreeModel();
        model.setRoot(FileTreeModel.getAvailableRoots().get(0));
		
        cb = new JComboBox(FileTreeModel.getAvailableRoots().toArray());
                
        JTree tree = new JTree(model);
        ToolTipManager.sharedInstance().registerComponent(tree);
        tree.setCellRenderer(new FileTreeRenderer());
        JScrollPane scrollPane = new JScrollPane(tree);
        
        cb.addActionListener(this);
        
        frame.add(cb, BorderLayout.NORTH);
        frame.add(scrollPane, BorderLayout.CENTER);
        
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }
}
